from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from configs import dburl
import pymysql
pymysql.install_as_MySQLdb()

app = Flask(__name__)
# 配置数据库的连接参数
#######################################cfg
app.config['SQLALCHEMY_DATABASE_URI'] = dburl
#######################################
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

app.app_context().push()

class User(db.Model):
    __tablename__ = 'user'
 
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    account = db.Column(db.String(40, 'utf8_general_ci'), nullable=False, info='用户名')
    password = db.Column(db.Text(collation='utf8_general_ci'), nullable=False, info='密码')
    access = db.Column(db.Integer, server_default=db.FetchedValue(), info='权限')
    name = db.Column(db.String(40, 'utf8_general_ci'), server_default=db.FetchedValue(), info='姓名')
    email = db.Column(db.Text(collation='utf8_general_ci'), info='邮箱')
    phone = db.Column(db.String(12, 'utf8_general_ci'), server_default=db.FetchedValue(), info='手机号（预留）')
    salt = db.Column(db.String(16, 'utf8_general_ci'), server_default=db.FetchedValue(), info='密码盐（预留）')
    verifycode = db.Column(db.String(6, 'utf8_general_ci'), server_default=db.FetchedValue(), info='验证码')
    verifydate = db.Column(db.DateTime, info='验证码有效期')
    hosptital = db.Column(db.String(255, 'utf8_general_ci'), server_default=db.FetchedValue(), info='属于哪个医院（预留）')
    creator = db.Column(db.String(40, 'utf8_general_ci'), info='谁创建的')

    def __init__(self,account,password,name,access,email,phone,hosptital,creator):
        self.account = account
        self.password = password
        self.name = name
        self.access = access
        self.email = email
        self.phone = phone
        self.hosptital = hosptital
        self.creator = creator
        
        
if __name__ == '__main__':
    db.drop_all()        
    db.create_all()
